﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;

public class ScreenFader : Singleton<ScreenFader>
{
    [CompilerGenerated]
    private static Func<float> <>f__am$cache3;
    [CompilerGenerated]
    private static Action<float> <>f__am$cache4;
    public static float fadeInDuration = 0.2f;
    public static float fadeOutDuration = 0.2f;
    [SerializeField]
    private CanvasGroup m_canvasGroup;

    [DebuggerHidden]
    private static IEnumerator _Fade(Func<YieldInstruction> action)
    {
        return new <_Fade>c__IteratorF { action = action, <$>action = action };
    }

    public static void CoverUp()
    {
        Singleton<ScreenFader>.Instance.StopAllCoroutines();
        value = 1f;
    }

    public static Coroutine Fade(Action action)
    {
        <Fade>c__AnonStorey6A storeya = new <Fade>c__AnonStorey6A {
            action = action
        };
        return Fade(new Func<YieldInstruction>(storeya.<>m__FD));
    }

    public static Coroutine Fade(IEnumerator coroutine)
    {
        <Fade>c__AnonStorey6B storeyb = new <Fade>c__AnonStorey6B {
            coroutine = coroutine
        };
        return Fade(new Func<YieldInstruction>(storeyb.<>m__FE));
    }

    public static Coroutine Fade(Func<YieldInstruction> action)
    {
        return Singleton<ScreenFader>.Instance.StartCoroutine(_Fade(action));
    }

    public static Coroutine Fadeout()
    {
        if (<>f__am$cache3 == null)
        {
            <>f__am$cache3 = () => Time.unscaledDeltaTime;
        }
        if (<>f__am$cache4 == null)
        {
            <>f__am$cache4 = delegate (float v) {
                value = v;
            };
        }
        return Singleton<ScreenFader>.Instance.StartAnimateFloat(1f, 0f, fadeOutDuration, <>f__am$cache3, <>f__am$cache4, null);
    }

    public static bool isActive
    {
        get
        {
            return Singleton<ScreenFader>.Instance.m_canvasGroup.gameObject.activeSelf;
        }
        set
        {
            Singleton<ScreenFader>.Instance.m_canvasGroup.gameObject.SetActive(value);
        }
    }

    public static bool isFading
    {
        get
        {
            return isActive;
        }
    }

    private static float value
    {
        get
        {
            return Singleton<ScreenFader>.Instance.m_canvasGroup.alpha;
        }
        set
        {
            isActive = value > 0f;
            Singleton<ScreenFader>.Instance.m_canvasGroup.alpha = value;
        }
    }

    [CompilerGenerated]
    private sealed class <_Fade>c__IteratorF : IDisposable, IEnumerator, IEnumerator<object>
    {
        internal object $current;
        internal int $PC;
        internal Func<YieldInstruction> <$>action;
        private static Func<float> <>f__am$cache5;
        private static Action<float> <>f__am$cache6;
        private static Func<float> <>f__am$cache7;
        private static Action<float> <>f__am$cache8;
        internal YieldInstruction <yi>__0;
        internal Func<YieldInstruction> action;

        private static float <>m__100()
        {
            return Time.unscaledDeltaTime;
        }

        private static void <>m__101(float v)
        {
            ScreenFader.value = v;
        }

        private static float <>m__102()
        {
            return Time.unscaledDeltaTime;
        }

        private static void <>m__103(float v)
        {
            ScreenFader.value = v;
        }

        internal void <>m__FF()
        {
            if (this.action != null)
            {
                this.<yi>__0 = this.action();
            }
        }

        [DebuggerHidden]
        public void Dispose()
        {
            this.$PC = -1;
        }

        public bool MoveNext()
        {
            uint num = (uint) this.$PC;
            this.$PC = -1;
            switch (num)
            {
                case 0:
                    this.<yi>__0 = null;
                    Singleton<ScreenFaderHelper>.Instance.StartWaitForSeconds(ScreenFader.fadeInDuration, new Action(this.<>m__FF));
                    if (<>f__am$cache5 == null)
                    {
                        <>f__am$cache5 = new Func<float>(ScreenFader.<_Fade>c__IteratorF.<>m__100);
                    }
                    if (<>f__am$cache6 == null)
                    {
                        <>f__am$cache6 = new Action<float>(ScreenFader.<_Fade>c__IteratorF.<>m__101);
                    }
                    this.$current = Singleton<ScreenFader>.Instance.StartAnimateFloat(0f, 1f, ScreenFader.fadeInDuration, <>f__am$cache5, <>f__am$cache6, null);
                    this.$PC = 1;
                    goto Label_0144;

                case 1:
                    if (this.<yi>__0 == null)
                    {
                        break;
                    }
                    this.$current = this.<yi>__0;
                    this.$PC = 2;
                    goto Label_0144;

                case 2:
                    break;

                case 3:
                    this.$PC = -1;
                    goto Label_0142;

                default:
                    goto Label_0142;
            }
            if (<>f__am$cache7 == null)
            {
                <>f__am$cache7 = new Func<float>(ScreenFader.<_Fade>c__IteratorF.<>m__102);
            }
            if (<>f__am$cache8 == null)
            {
                <>f__am$cache8 = new Action<float>(ScreenFader.<_Fade>c__IteratorF.<>m__103);
            }
            this.$current = Singleton<ScreenFader>.Instance.StartAnimateFloat(1f, 0f, ScreenFader.fadeOutDuration, <>f__am$cache7, <>f__am$cache8, null);
            this.$PC = 3;
            goto Label_0144;
        Label_0142:
            return false;
        Label_0144:
            return true;
        }

        [DebuggerHidden]
        public void Reset()
        {
            throw new NotSupportedException();
        }

        object IEnumerator<object>.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }

        object IEnumerator.Current
        {
            [DebuggerHidden]
            get
            {
                return this.$current;
            }
        }
    }

    [CompilerGenerated]
    private sealed class <Fade>c__AnonStorey6A
    {
        internal Action action;

        internal YieldInstruction <>m__FD()
        {
            this.action();
            return null;
        }
    }

    [CompilerGenerated]
    private sealed class <Fade>c__AnonStorey6B
    {
        internal IEnumerator coroutine;

        internal YieldInstruction <>m__FE()
        {
            return Singleton<ScreenFaderHelper>.Instance.StartCoroutine(this.coroutine);
        }
    }
}

